// Copyright 2011 Jefferson Willian
// willmont7@gmail.com

#include <cstdio>
#include <queue>

#define INF 1000000

using std::priority_queue;

int main() {
  priority_queue<int> pqueue;

  int n, m;
  int lower = INF;
  int t;

  scanf("%d%d", &n, &m);

  for (int i = 0;i < m;i++) {
    scanf("%d", &t);
    if (t < lower) lower = t;
    pqueue.push(t);
  }

  for (int i = m;i < n;i++) {
    scanf("%d", &t);
    if (t > lower)
      pqueue.push(t);
  }

  for (int i = 0;i < m;i++, pqueue.pop())
    printf("%d\n", pqueue.top());

  return 0;
}
